package lesson3.pages.locators.site;

import static lesson3.api.helpers.PageHelper.INDEX_PAGE;
import static lesson3.api.helpers.PageHelper.REGISTRATION_PAGE;
import static lesson3.api.helpers.PageHelper.USER_MENU;

import java.util.Map;

import lesson3.api.ApplicationManager;
import lesson3.api.models.LocatorModel;
import lesson3.pages.locators.LocatorBase;
import lesson3.pages.locators.page.PageLocators;

public class RedmineLocators extends LocatorBase implements SiteLocators
{
	public RedmineLocators(ApplicationManager p_app)
	{
		super(p_app);
	}

	// Index Page Locators
	public class IndexPageLocators implements PageLocators
	{
		@Override
		public void setPage()
		{
			setLocator("page", "url", "/");
		}

		@Override
		public void setLocators()
		{
			setLocator("txtLogin", "id", "username");
			setLocator("txtPassword", "id", "password");
			setLocator("btnLogin", "name", "login");
			setLocator("linkRegistration", "css", "a.register");
			setLocator("blockNotification", "id", "flash_notice");
		}

		@Override
		public Map<String, LocatorModel> getLocators()
		{
			setPage();
			setLocators();
			return locators;
		}
	}

	// Registration Page Locators
	public class RegistrationPageLocators implements PageLocators
	{
		@Override
		public void setPage()
		{
			setLocator("page", "url", "/account/register");
		}

		@Override
		public void setLocators()
		{
			setLocator("txtLogin", "id", "user_login");
			setLocator("txtPassword", "id", "user_password");
			setLocator("txtPasswordConfirm", "id", "user_password_confirmation");
			setLocator("txtFirstNname", "id", "user_firstname");
			setLocator("txtLastName", "id", "user_lastname");
			setLocator("txtEmail", "id", "user_mail");
			setLocator("txtSkype", "id", "user_custom_field_values_7");
			setLocator("txtPhone", "id", "user_custom_field_values_10");
			setLocator("txtDepartment", "id", "user_custom_field_values_28");
			setLocator("txtOccupation", "id", "user_custom_field_values_31");
			setLocator("selectLanguage", "id", "user_language");
			setLocator("btnRegistration", "name", "commit");
		}

		@Override
		public Map<String, LocatorModel> getLocators()
		{
			setPage();
			setLocators();
			return locators;
		}
	}

	// User Menue Locators
	public class UserMenuLocators implements PageLocators
	{

		@Override
		public void setLocators()
		{
			setLocator("linkLogout", "css", "a.logout");
		}

		@Override
		public void setPage()
		{

		}

		@Override
		public Map<String, LocatorModel> getLocators()
		{
			setLocators();
			return locators;
		}
	}

	@Override
	public PageLocators getPageLocators()
	{
		if (app.testPage.contains(INDEX_PAGE))
		{
			return new IndexPageLocators();
		}
		else if (app.testPage.contains(REGISTRATION_PAGE))
		{
			return new RegistrationPageLocators();
		}
		else if (app.testPage.contains(USER_MENU))
		{
			return new UserMenuLocators();
		}

		return null;
	}

}
